package com.kaigejava.juc.volatitle;

/**
 * @author kaigejava
 * 多线程下DCL(double chekc lock)：使用双检锁机制
 */
public class SingletonDemo3 {
    private static  SingletonDemo3 instance = null;
    private SingletonDemo3(){
        System.out.println("======开始调用私有构造器了。线程名称："+Thread.currentThread().getName());
    }
    public  static synchronized SingletonDemo3 getInstance(){
        if(null == instance){
            synchronized(SingletonDemo3.class){
                if(null == instance){
                    instance = new SingletonDemo3();
                }
            }
        }
        return instance;
    }
    public static void main(String[] args) {
        for(int i = 0;i<10;i++){
            new Thread(()->{
                SingletonDemo3.getInstance();
            },"线程"+(i+1)).start();
        }
    }
}
